<template>
  <div class="review">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="评分">
        <el-rate v-model="form.score" style="margin-top: 10px"></el-rate>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <el-input
          type="textarea"
          v-model="form.content"
          :rows="6"
          placeholder="请输入评论内容"
        ></el-input>
      </el-form-item>
      <el-form-item style="text-align: right">
        <el-button type="primary" @click="handleSubmit('form')" size="small"
          >提交</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        pid: '0', //父级节点(评价类型不传)
        resId: '', //资源ID
        content: '',
        score: 5, //评分
        type: '1', //节点类型；1-评价，2-回复
        resType: '2', //资源类型；1-课程，2-知识点，3-…
      },
      rules: {
        content: [
          { required: true, message: '请输入评论内容', trigger: 'blur' },
        ],
      },
    }
  },
  mounted() {},
  methods: {
    handleSubmit(form) {
      let { cId } = this.$route.query
      this.form.resId = cId
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add()
        }
      })
    },
    async add() {
      await this.$store.dispatch('addSysEvaluate', this.form)
      this.form = this.$options.data().form
      this.$bus.$emit('getMyReviewList')
      this.$bus.$emit('refreshAllReviewList')
    },
  },
}
</script>
<style scoped lang="scss">
</style>